package com.zunipe.chat;

import android.app.Application;
import android.content.SharedPreferences;

public class ChatApplication extends Application {
    private static ChatApplication instance;
    private String username;
    private SharedPreferences config;
    private boolean isChatServiceRunning;

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;

        config = getSharedPreferences("config", MODE_PRIVATE);
        username = config.getString("username", "");
    }

    public static ChatApplication getInstance() {
        return instance;
    }

    public void setUsername(String username) {
        this.username = username;
        SharedPreferences.Editor edit = config.edit();
        edit.putString("username", username);
        edit.apply();
    }

    public String getUsername() {
        return this.username;
    }

    public boolean isChatServiceRunning() {
        return this.isChatServiceRunning;
    }

    public void setChatServiceRunning(boolean flag) {
        this.isChatServiceRunning = flag;
    }
}
